<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <script src="../script/api.js"></script>
    <style>

    </style>
</head>

<body>
    <header id='header' class="aui-bar aui-bar-nav" style="background-color: #03a9f4">
        <a class="aui-pull-left aui-btn" onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="middle">
           发货计划查询
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:0px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">发货计划号</div>
                    <input type="text" class="aui-input" placeholder="请 扫码/输入发货计划号" style="width: 80%;font-size: 16px;"
                        id="name"  />
                    <i class="aui-input-addon aui-iconfont aui-icon-scan " style="padding-right:10px;font-size: 1.6rem"
                        onclick="doScan();"></i>
                </div>
            </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">发货日期</div>
                        <div class="aui-list-item-input" onclick="timePicker();">
                            <input type="text" placeholder="选择日期" id="invoicedate" class="aui-input"
                                />
                        </div>

                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">客户</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请选择/扫描客户" id="customerName" value=""
                                onclick="getIdSelector();" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectCustomer()"></i>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">物料编码</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请输入物料编码" id="mrlCode" value=""
                                 />
                        </div>

                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">规格</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请输入规格" id="drawing" value=""
                                />
                        </div>

                    </div>
                </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="doSearch()">查询</div>
        </div>
        <ul class="ui-selectee" id="tbodyHtml">


        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script>
    var relworkcell = "";
    var customerGid = ""; //客户GID
    var customerCode = ""; //客户编码
    var customerName = ""; //客户名称
    var codesub = ""; //菜单路由参数 子业务类型
    var title = ""; //菜单名

    apiready = function() {
        $("#name").focus();
        idSelector = "name";
        //今天的时间
        var dayS = new Date();
        dayS.setTime(dayS.getTime());
        var mm = (dayS.getMonth() + 1) >= 10 ? (dayS.getMonth() + 1) : "0" + (dayS.getMonth() + 1);
        var dd = dayS.getDate() >= 10 ? dayS.getDate() : "0" + dayS.getDate();
        var start =
            dayS.getFullYear() + "-" + mm + "-" + dd;

        //菜单参数
        var query = api.pageParam.query;

        codesub = query.codesub;
        title = query.title;
        if (title != undefined && title != null && title != "") {
            document.getElementById("middle").innerHTML = title + "查询";
        }
        doSearch(start);
    }
    //时间选择器
    function timePicker(id) {
        api.openPicker({
            type: 'dateTime',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#invoicedate").val(date);
            }
        });
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }
//选择客户
function goSelectCustomer() {
        api.openWin({
            name: 'uwmSelectCustomer',
            url: 'uwmSelectCustomer.html',
            pageParam: {
                name: "wmInvoiceInfo",
            }
        });
    }
     //客户选择后回调函数
     function setCustomer(id, code, name) {
        customerGid = id;
        customerCode = code;
        customerName = name;
        document.getElementById('customerName').value= code+":"+name;
        $("#customerName").focus();
        idSelector = "customerName";
    }

    //客户扫描校验
    function getCustomer(code, inputId) {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem('un');
        var url = serverUrl + "/app/getCustomer";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                customerCode: code,
                un:un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    customerGid = list[0].customerGid;
                    customerCode = list[0].customerCode ;
                    customerName = list[0].customerName;
                    document.getElementById(inputId).value = customerCode+ ":" + customerName;
                    $("#customerCode").focus();
                    idSelector = "customerCode";

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });

                    $("#customerCode").focus();
                    $("#customerCode").select();
                }
            }
        });
    }

    //查询
    function doSearch(dateS) {
        //光标所在id
        var idSelector = "";
        var name = ""; //发货单号
        //发货单号
        var name = $("#name").val();
        //日期
        var invoicedate = $("#invoicedate").val();
        //客户名称
        var customerName = $("#customerName").val();
        //规格
        var drawing = $("#drawing").val();

        //物料编码
        var mrlCode = $("#mrlCode").val();
        if (name != null && name != undefined && name != "") {
            name = name.trim();
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/wminvoiceinfoListNew";
        var data = {
            values: {
                code: name,
                // statusList: "0,1",//筛选创建状态和发货中状态发货单
                invoicedate: invoicedate,
                drawing:drawing,
                mrlCode:mrlCode,
                customerCode:customerCode,
                subBussinessType:codesub,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<li class='sortable ui-selectee ui-sortable'>";
                        html += "<ul class='aui-list aui-media-list ui-selectee'>";
                        html += "<li class='aui-list-item  ui-selectee'>";
                        html += "<div class='aui-media-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>发货计划号</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].code + "</div>";
                        html += "</div>";
                        
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>发货日期</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].invoicedate + "</div>";
                        html += "</div>";

                      
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>计划发货数量</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].planQty + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>已绑定数量</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].bdQty + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title' style='width: 45%;'>实际发货数量</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 0.1rem;'>" + list[i].actualQty + "</div>";
                        html += "</div>";
                        
                        html += "<div class='aui-list-item-right aui-btn ui-selectee' " +
                            "onclick='goPageDetail(\"" + list[i].code +"\",\""+ list[i].sysid+"\");'>发货</div>";
                        
                        html += "<div class='aui-list-item-right aui-btn ui-selectee' " +
                            "onclick='setPicture(\"" + list[i].code +"\",\""+ list[i].sysid+"\");'>图片上传</div>";
                            
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</li>";
                        html += "</ul>";
                        html += "</li>";
                    }
                    // console.log("htmlhtml",html);
                    $api.html($api.byId("tbodyHtml"), html);
                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    function test() {
        $api.html($api.byId("tbodyHtml"), "");
    }
    //跳转详情页面
    function goPageDetail(invoiceplancode,sysid) {
        //打开页面
        api.openWin({
            name: 'wmInvoiceInfoDetail',
            url: 'wmInvoiceInfoDetail' + '.html',
            pageParam: {
                invoiceplancode: invoiceplancode,
                invoiceinfoid:sysid, //wgh241016 这里不是发货单id，是计划id
                subBussinessType: codesub,
                titleText:title,
            },
        });
    }
    //跳转图片上传页面
    function setPicture(invoiceplancode,sysid) {
        //打开页面
        api.openWin({
            name: 'paSetPicture',
            url: 'paSetPicture' + '.html',
            pageParam: {
                invoiceplancode: invoiceplancode,
                invoiceinfoid:sysid,
            },
        });
    }
        

     //扫描
     function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            //发货单号
            if (idSelector == 'name') {

                $("#name").val(ret);
                refreshData();

            } 
        });
    }

    //发货单号监听回车事件
    $("#name").on('keypress', function(e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            refreshData();
        }
    });

    //刷新数据
    function refreshData() {
        var dayS = new Date();
        dayS.setTime(dayS.getTime());
        var mm = (dayS.getMonth() + 1) >= 10 ? (dayS.getMonth() + 1) : "0" + (dayS.getMonth() + 1);
        var dd = dayS.getDate() >= 10 ? dayS.getDate() : "0" + dayS.getDate();
        var start =
            dayS.getFullYear() + "-" + mm + "-" + dd;
        doSearch(start);
    }
</script>

</html>
